package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcExaminateEntity;
import com.dhcc.cdc.busi.service.ICdcExaminationService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 检查报告
 * 
 * @ClassName: CdcExaminationController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:08
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcexamination")
public class CdcExaminationController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcexamination/";

	@Autowired
	private ICdcExaminationService cdcExaminationService;
	

    /**
     * 跳转到检查报告列表首页
     */
    @RequestMapping("")
    @Permission("cdcexamination:list")
    public String index() {
        return PREFIX + "cdcexamination.html";
    }
	
    /**
     * 跳转到新增检查报告
     */
    @RequestMapping("/to_add")
    @Permission("cdcexamination:add")
    public String toAdd() {
        return PREFIX + "cdcexamination_add.html";
    }
	
	/**
     * 跳转到修改检查报告
     */
    @RequestMapping("/to_update/{cdcExaminationId}")
    @Permission("cdcexamination:update")
    public String toUpdate(@PathVariable Long cdcExaminationId, Model model) {
        CdcExaminateEntity cdcExamination = this.cdcExaminationService.selectById(cdcExaminationId);
        model.addAttribute("cdcExamination",cdcExamination);
        return PREFIX + "cdcexamination_edit.html";
    }

    /**
     * 获取检查报告列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcexamination:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcExaminateEntity> page = new PageFactory<CdcExaminateEntity>().defaultPage();

        List<CdcExaminateEntity> result = null;
        if((CommonUtil.isNotEmpty(params.get("NotQuery")))&&(params.get("NotQuery").toString().equals("true"))){
            result = new ArrayList<CdcExaminateEntity>();
        }else{
            result = this.cdcExaminationService.page(page,params);
        }
        page.setRecords((List<CdcExaminateEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增检查报告
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcexamination:add")
    @BussinessLog(value = "新增检查报告")
    public Object add(CdcExaminateEntity cdcExamination) {
        if (CommonUtil.isOneEmpty(cdcExamination)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcExamination.insert();
        return R.ok();
    }

    /**
     * 删除检查报告
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcexamination:delete")
    @BussinessLog(value = "删除检查报告")
    public Object delete(@RequestParam Long cdcExaminationId) {
	
        this.cdcExaminationService.deleteById(cdcExaminationId);

        return R.ok();
    }

    /**
     * 修改检查报告
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcexamination:update")
    @BussinessLog(value = "修改检查报告")
    public Object update(CdcExaminateEntity cdcExamination) {
        if (CommonUtil.isOneEmpty(cdcExamination)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcExaminateEntity old = this.cdcExaminationService.selectById(cdcExamination.getId());

        old.setEpisodeId(cdcExamination.getEpisodeId());
        old.setXcode(cdcExamination.getXcode());
        old.setExamNum(cdcExamination.getExamNum());
        old.setBusExamReportStatusId(cdcExamination.getBusExamReportStatusId());
        old.setDescription(cdcExamination.getDescription());
        old.setExamDesc(cdcExamination.getExamDesc());
        old.setResultDesc(cdcExamination.getResultDesc());
        old.setRepUserName(cdcExamination.getRepUserName());
        old.setRepDate(cdcExamination.getRepDate());
        old.setRegUserName(cdcExamination.getRegUserName());
        old.setRegDate(cdcExamination.getRegDate());
        old.setBsOrdexecId(cdcExamination.getBsOrdexecId());
        old.setDataId(cdcExamination.getDataId());
        old.setIsActive(cdcExamination.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
